public class BackgroundSpanner{

  PImage backgrounds[];
  float currentXLocation, currentYLocation;
  int fingerId, amountToMoveX, amountToMoveY;

  public BackgroundSpanner(PImage backgrounds[], float startingXLocation, float startingYLocation){
    fingerId = -1;
    this.backgrounds = backgrounds;
    currentXLocation = startingXLocation;
    currentYLocation = startingYLocation;
  }

  public void moveLocation(int moveX, int moveY, int id){
    amountToMoveX = moveX;
    amountToMoveY = moveY;
    fingerId = id;
  }

  public void continueToMove(){
    currentXLocation += amountToMoveX;
    currentYLocation += amountToMoveY; 
  }

  public void display(){
    if(fingerId != -1){
      continueToMove(); 
    }
    if(currentXLocation > width/2.0){
      if(currentYLocation > height/2.0){
        image(backgrounds[0], currentXLocation - width, currentYLocation - height);
        image(backgrounds[1], currentXLocation, currentYLocation - height);
        image(backgrounds[3], currentXLocation - width, currentYLocation);
        image(backgrounds[4], currentXLocation, currentYLocation); 
      } 
      else {
        image(backgrounds[3], currentXLocation - width, currentYLocation);
        image(backgrounds[4], currentXLocation, currentYLocation);
        image(backgrounds[6], currentXLocation - width, currentYLocation + height);
        image(backgrounds[7], currentXLocation, currentYLocation + height); 
      }
    } 
    else {
      if(currentYLocation > height/2.0){
        image(backgrounds[1], currentXLocation, currentYLocation - height);
        image(backgrounds[2], currentXLocation, currentYLocation - height);
        image(backgrounds[4], currentXLocation, currentYLocation);
        image(backgrounds[5], currentXLocation + width, currentYLocation); 
      } 
      else {
        image(backgrounds[4], currentXLocation, currentYLocation);
        image(backgrounds[5], currentXLocation + width, currentYLocation);
        image(backgrounds[7], currentXLocation, currentYLocation + height);
        image(backgrounds[8], currentXLocation + width, currentYLocation + height); 
      }
    }
  }

}

